package cn.csc.framework.redisson.lock.config;

import cn.csc.framework.redisson.lock.aspect.LockInterceptor;
import cn.csc.framework.redisson.lock.util.DistributedLockUtil;
import cn.csc.framework.redisson.lock.util.RedisUtil;
import org.redisson.api.RedissonClient;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;

@AutoConfiguration
public class RedisAutoConfiguration {

    @Bean
    public LockInterceptor lockInterceptor(RedissonClient redissonClient) {
        return new LockInterceptor(redissonClient);
    }


    @Bean
    @ConditionalOnBean(value = RedisTemplate.class)
    public RedisUtil redisUtil(RedisTemplate redisTemplate) {
        return new RedisUtil(redisTemplate);
    }

    @Bean
    public DistributedLockUtil distributedLockUtil(RedissonClient redissonClient){
        return new DistributedLockUtil(redissonClient);
    }
}
